package practica3;

import java.io.*;
import antlr.collections.AST;
import antlr.ANTLRException;


public class Procesador {
	public static void main(String args[]) {
		if (args.length == 0) {
			try {
				InputStreamReader isr = new InputStreamReader(System.in);
				BufferedReader br = new BufferedReader(isr);
				String linea = br.readLine();
				while (!linea.equals("$")) {
					Analex analex = null;
					AnasintTeclado anasint = null;
					analex = new Analex(new StringReader(linea));
					anasint = new AnasintTeclado(analex);
					anasint.entrada();
					linea = br.readLine();
				}
			}
			catch(ANTLRException ae) {
				System.err.println(ae.getMessage());
			}
			catch(IOException ioe) {
				System.err.println(ioe.getMessage());
			}
		}
		else {
			try {
				FileInputStream fis = new FileInputStream(args[0]);
				Analex analex = null;
				Anasint anasint = null;
				analex = new Analex(fis);
				anasint = new Anasint(analex);
				anasint.entrada();
			}catch(ANTLRException ae) {
				System.err.println(ae.getMessage());
			}
			catch(FileNotFoundException fnfe) {
				System.err.println("No se encontró el fichero");
			}
		}
	}
}